package com.mornstar.econvent.auth.controller;

import cn.hutool.core.util.IdUtil;
import com.mornstar.common.support.Kv;
import com.wf.captcha.SpecCaptcha;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 认证模块 - 常规登录认证（账号密码）
 *
 * @author xiekun
 */
@RestController
@AllArgsConstructor
@RequestMapping("/auth")
public class AuthController {
    @GetMapping("/captcha")
    public Kv captcha() {
        SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
        String verCode = specCaptcha.text().toLowerCase();
        String key = IdUtil.randomUUID();
        // 存入redis并设置过期时间为5分钟
        //bladeRedis.setEx(CacheNames.CAPTCHA_KEY + key, verCode, Duration.ofMinutes(5));
        // 将key和base64返回给前端
        return Kv.create().set("key", key).set("image", specCaptcha.toBase64());
    }
}
